using System;
using OneDayModel.Interfaces;
using OneDayModel.Model;
using OneDayModel.PresentationLogic;
using OneDayModel.Tests.Mocks;

namespace OneDayModel.Tests.Fits.UIUsers
{
    public class UploadPictureUser : IUploadPictureUI
    {
        private string pictureName;
        private string albumName;
        private readonly IRepository repository;
        private SessionContext sessionContext = new SessionContext();
        private string shownError;


        public UploadPictureUser()
        {
            repository = new MockRepository();
            new UploadPictureUILogic(this, new AlbumsWorksModel(repository, new MockFileSystem(), this.sessionContext));
        }

        public string ShownError
        {
            get { return shownError; }
        }

        public void SetPictureName(string name)
        {
            pictureName = name;
        }

        public void SetAlbumName(string name)
        {
            albumName = name;
        }

        public void UploadPicture()
        {
            if (OnUploadPicture != null)
            {
                IUploadedFile uploadedFile = new UploadedFileMock(pictureName);
                OnUploadPicture(this, new UploadPictureArgs(albumName, uploadedFile));
            }
        }

        #region IUploadPictureUI Members

        public event EventHandler<UploadPictureArgs> OnUploadPicture;

        public void ShowError(string message)
        {
            shownError = message;
        }

        #endregion

        public void SetContextUser(string alias)
        {
            IUser owner = repository.GetUserByAlias(alias);

            sessionContext.User = owner;

            ((IOnlineCache)repository).RegisterUserOnline(alias);
        }
    }
}